{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0UEwW_kxbBan"
      },
      "source": [
        "# Exercise Set 2\n",
        "**Q1.** Re-write the **Charge/discharge:** constraints using indicator constraints. Remember to consider what happens when $z_{b,t} = 1$ and when $z_{b,t} = 0$\n",
        "\n",
        "Define $z_t \\in \\{0,1\\}, t \\in T$.\n",
        "$$\n",
        "\\begin{align*}\n",
        "f^{in}_{b,t} &\\leq 20*z_{b,t} &\\forall b \\in B, t \\in T \\\\\n",
        "f^{out}_{b,t} &\\leq 20*(1-z_{b,t}) &\\forall b \\in B, t \\in T\n",
        "\\end{align*}\n",
        "$$"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Hv_YnclGhw5x"
      },
      "outputs": [],
      "source": [
        "m.addConstrs((       ???????????         ), name = \"zis0\")\n",
        "m.addConstrs((       ???????????         ), name = \"zis1\")\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YH5CEz4wdUEh"
      },
      "source": [
        "The multiple scenarios API is restricted. For example, it is not possible to explicitly\n",
        "- Add/remove variables or constraints\n",
        "- Change the variable types\n",
        "- Change the sense of constraints\n",
        "\n",
        "However, we can get around some of the restrictions using some tricks.\n",
        "\n",
        "Assume `ScenarioNumber` and `ScenNName` parameters are already set for each of the below.\n",
        "______\n",
        "To remove a variable, set its bounds to zero.\n",
        "\n",
        "**Q2.** Write a `for` loop and `gurobipy` code to remove the flow in and flow out for `Battery0` in time periods 0 to 49.\n",
        "______\n",
        "To add a variable to a scenario, add it to the base model with bounds set to zero and then change the bounds accordingly.\n",
        "\n",
        "**Q3.** Write `gurobipy` code to add a continuous variable $w_t, t\\in T$ to the base model `m` such that it's \"not in\" this model as described above. Then write a `for` loop to add it to a scenario with an *upper bound* of 100.\n",
        "______\n",
        "\n",
        "To remove a constraint, change its RHS values to GRB.INFINITY/-GRB.INFINITY.\n",
        "\n",
        "**Q4.** We defined $v_{b,t} = 1$ when battery $b$ is below a depth of discharge α (say 0.3) and 0 otherwise. Supposed we had a hard constraint on the number of times both batteries together could go below their depth, with that limit to be 15. And say we stored (set the constraint equal to) this constraint as `depth_limit`.\n",
        "\n",
        "$$\n",
        "\\begin{equation}\n",
        "\\sum_{b,t} v_{b,t} \\le C\n",
        "\\end{equation}\n",
        "$$\n",
        "\n",
        "Add a constraint to the base model `m` for the number of times either battery could go below its depth. Write the `gurobipy` code to remove this constraint.\n",
        "______"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "AlS6ui8R8BFj"
      },
      "outputs": [],
      "source": [
        "#Q2.\n",
        "\n",
        "\n",
        "\n",
        "#Q3.\n",
        "\n",
        "\n",
        "\n",
        "#Q4.\n",
        "v = m.addVars(time_periods, vtype=GRB.BINARY, name = 'v')\n",
        "\n",
        "\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
